<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of XMLGen
 *
 * @author Tomek
 */
class XMLGen
{

//put your code here
    private $employees = array();
    private $jobs = array();
    private $dates = array();
    private $locations = array();
    private $jobsOffer = array();
    private $href = array();
    private $XMLName = '';

    public function __construct($XMLName, $employees, $jobs, $dates, $locations, $jobsOffer, $href)
    {
        if (is_array($employees))
            $this->employees = $employees;
        if (is_array($jobs))
            $this->jobs = $jobs;
        if (is_array($dates))
            $this->dates = $dates;
        if (is_array($locations))
            $this->locations = $locations;
        if (is_array($jobsOffer))
            $this->jobsOffer = $jobsOffer;
        if (is_array($href))
            $this->heref = $href;
        if (isset($XMLName))
            $this->XMLName = $XMLName;
    }

    public function getEmployees()
    {
        echo '<pre>';
        var_dump($this->employees);
        echo '</pre>';
    }

    public function getJobs()
    {
        echo '<pre>';
        var_dump($this->jobs);
        echo '</pre>';
    }

    public function getDates()
    {
        echo '<pre>';
        var_dump($this->dates);
        echo '</pre>';
    }

    public function getLoc()
    {
        echo '<pre>';
        var_dump($this->locations);
        echo '</pre>';
    }

    public function getJobsOffer()
    {
        echo '<pre>';
        var_dump($this->jobsOffer);
        echo '</pre>';
    }

    public function getHref()
    {
        echo '<pre>';
        var_dump($this->href);
        echo '</pre>';
    }

    public function getName()
    {
        var_dump($this->XMLName);
    }

    public function generateXML()
    {
        $XMLDocument = new DOMDocument('1.0', 'utf-8');
        $XMLDocument->formatOutput = true;

        $Oferty = $XMLDocument->appendChild($XMLDocument->createElement('Oferty'));

        $licznik = count($jobs);
        for ($i = 0; $i < $licznik; ++$i)
        {
            $Oferta = $Oferty->appendChild($XMLDocument->createElement('Oferta'));
            $Oferta->appendChild($XMLDocument->createElement('Praca', html_entity_decode($this->$jobs[$i])));
            $Oferta->appendChild($XMLDocument->createElement('Pracodawca', html_entity_decode($this->$employees[$i])));
            $Oferta->appendChild($XMLDocument->createElement('Lokalizacja', html_entity_decode($this->$locations[$i])));
            $Oferta->appendChild($XMLDocument->createElement('Data', html_entity_decode($this->$dates[$i])));
            $Oferta->appendChild($XMLDocument->createElement('Link', html_entity_decode($this->$href[$i])));
            $Oferta->appendChild($XMLDocument->createElement('Oferta', html_entity_decode($this->$jobOffer[$i])));
        }
        file_put_contents($this->XMLName, $XMLDocument->saveXML());
    }

}

?>
